
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title> 订单查询</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="demo.css" rel="stylesheet" type="text/css" />
    <script src="scripts/boot.js" type="text/javascript"></script>
	<style>
	td{
    //text-align:center;
	}
	
	.zengpin{
        background:#fceee2;
    }
	</style>
    
</head>
<body >
<div id="panel1" class="mini-panel" title="查询条件" iconCls="icon-search" style="width:100%;height:250px;" 
  showToolbar="true" showCollapseButton="true" showFooter="true" allowResize="true" collapseOnTitleClick="true">
   
 <div style="padding-bottom:5px;">
        
        客户代码:  <div class="mini-autocomplete" style="width:15.2%;margin-left: 4px"  popupWidth="400" textField="id" valueField="id"  id='U_CardCode' name='U_CardCode'
        url="/sale/getOCRDByCode" value="" text=""  onvaluechanged="">     
        <div property="columns">
            <div header="客户代码" field="id" width="30"></div>
            <div header="客户名称" field="text"></div>
        </div>
    </div>
             
		<span>手机号码：</span><input type="text" id="U_Phone" name='U_Phone' style='width:15%'  />
		<span>持卡人姓名&nbsp;&nbsp;&nbsp;：</span><input type="text" id="U_ownname"  readonly=''style='width:15%' />
		<span>单据&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日期：</span>
		<input id="docDate1" class="mini-datepicker"  format='yyyy-MM-dd' valueType='string' style='width:8%;margin-left:-4px'/>
		<input id="docDate2" class="mini-datepicker"  format='yyyy-MM-dd' valueType='string' style='width:8%' />
		<br/>
		<span>物料名称：</span><input type="text" id="U_ItemName" name='U_ItemName' style='width:15%'/>
		<span>订 &nbsp;单&nbsp;号：</span><input type="text" id="U_OrderId" name='U_OrderId'style='width:15%'/>
		<span>物料编号&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：</span><input type="text" id="U_ItemCode"  name='U_ItemCode'style='width:15%' />
		<span>投诉&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间：</span>
		<input id="tousu_date1" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:8%;margin-left:-4px'/>
		<input id="tousu_date2" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:8%' />
		</br>
		<span>发货日期：</span>
		<input id="fahuo_date1" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:7.5%;margin-left:-4px'/>
		<input id="fahuo_date2" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:7.5%' />
		<span>发票类型：</span>
		<input id="U_InType"  style='width:15.3%;margin-left: -3.6px' class="mini-combobox" style="width:150px;" textField="text" valueField="id" 
    data='[
		{ "id": "1", "text": "增票" },
		{ "id": "2", "text": "普票" },
		{ "id": "3", "text": "候补" },
		{ "id": "4", "text": "保卡" },
		{ "id": "5", "text": "不开" },
		]' value="" showNullItem="true" required="true" allowInput="true"
    onvalidation="onComboValidation" 
/>  
		<span>其他号码&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：</span><input type="text" id="U_OTPhone"  name = 'U_OTPhone' style='width:15%' />
		
		<span>退货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间：</span>
		<input id="tuihuo_date1" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:8%;margin-left:-4px'/>
		<input id="tuihuo_date2" class="mini-datepicker" value="" format='yyyy-MM-dd' valueType='string' style='width:8%' />
		</br>
		<span>买家姓名：</span><input type="text" id="U_Cstname"  name='U_Cstname' style='width:15%' />
		<span>客户姓名：</span><input type="text" id="U_CardName"  name='U_CardName'  style='width:15%'/>
		<span>客户物料代码：</span><input type="text" id="U_CitemCd"  name='U_CitemCd'  style='width:15%'/>
		<span>客户物料名称：</span><input type="text" id="U_CitemNm"  name='U_CitemNm'  style='width:16%'/>
		</br>
		<span>快递单号：</span><input type="text" id="U_ExpNo" style='width:15%' />
		<div style="margin-left: -40px" id='statuslist' labelField="true" label="" name="countrys" class="mini-checkboxlist" repeatItems="9" repeatLayout="flow" url="status.txt" value="" textField="text" valueField="id" ></div>

		<div id="ck1" name="product" class="mini-checkbox" readOnly="false" text="全选" onvaluechanged="allchange"></div>     
	 </div>
		 <a onclick="search()"  class="mini-button" >查询</a>
    <a onclick="exportExcel()"  class="mini-button" >导出</a>
		 <a  onclick="celarvalue()"  class="mini-button"  >清空</a>  <a   class="mini-button"  onclick="updateConfig()" style="float: right;margin-right: 10px">保存表格顺序</a><br/> 
</div>


<div id="datagrid1" class="mini-datagrid" style="height:450px"
    url="/sap/sapdata.php" idField="id" allowResize="true"
    sizeList="[20,30,50,100,200]" pageSize="20"  ondrawcell="ondrawcell"  onrowdblclick="onButtonEdit"


>
    <div property="columns">


    </div>
</div>

   
    <script type="text/javascript">
		function show(){
		   jQuery('#show').toggle(
		   );
		}
		
		function show_hide(tag){
			  if(tag==1){
				  jQuery('#show').show();
				  //jQuery('#s_text').HTML('收起');
			  }else{
				  jQuery('#show').hide();
				  //jQuery('#s_text').HTML('展开');
			  }
		}
	
        function onfixed(e){
		if(e.value!=''&&!isNaN(e.value))
		return parseInt(e.value).toFixed(0)
		else
		return 0;
		}
		
	   function onfixed_2(e){
		if(e.value!=''&&!isNaN(e.value)&&e.value!='.000000')
		return parseInt(e.value).toFixed(2)
		else
		return 0;
		}
		
		 function onRenderer(e){
		if(e.value!='')
		return parseInt(e.value).toFixed(0)
		}
        
        mini.parse();
		mini.get("docDate1").setValue(getDate(7));
		mini.get("docDate2").setValue(getDate(0));
        var grid = mini.get("datagrid1");
        grid.set({
            url: "/sap/sapdata.php",
            style: "height:450px;",
            sizeList:"[20,30,50,100,200]",
            pageSize:"20", 
            columns: <?php echo $_SESSION['sapConfig']?>
          
        });
        grid.render(document.body);
        
        
        function updateConfig(){
         var data = mini.encode(grid.columns);
        
        $.ajax({
            url: "/UserConfig/updateSapConfig",
            data: { data: data },
            type:'post',
            async: true,
            success: function (text) {
            	if(text>0){
            		mini.alert('保存成功');
            	}else{
            		mini.alert('保存失败');
            	}
            	
              
            }
        });
        
        }
       //search();
	   
	   function celarvalue(){
	   clearsetsattuslist();
	   }
	   
	   function allchange(){
	     var t = mini.get("ck1");
            if(t.checked){
			mini.get('statuslist').setValue('1,2,3,4,5,6,7,8,9,10,11,12,13,14');
			}else{
			mini.get('statuslist').setValue(0);
			};
	   }
	   
	   function getDate(day){
	    var now = new Date();
		if(day!=0){
		var date = new Date(now.getTime() - day * 24 * 3600 * 1000);
		}else
		var date = new Date(now.getTime());
		
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate();
		return year + '-' + month + '-' + day ;
	   }
	   
	    function clearsetsattuslist() {
            var obj = mini.get("statuslist");
            obj.setValue("");
            
        }
        
		 var statusList =[
			{ "id": "1", "text": "未处理" },
			{ "id": "2", "text": "订单确认" },
			{ "id": "3", "text": "待处理" },
			{ "id": "4", "text": "异常订单" },
			{ "id": "5", "text": "未发货取消" },
			{ "id": "6", "text": "异常已导出" },
			{ "id": "7", "text": "已发订单确认短信" },
			{ "id": "8", "text": "可拣配" },
			{ "id": "9", "text": "已发货" },
			{ "id": "10", "text": "已发签收短信" },
			{ "id": "11", "text": "确认收货" },
			{ "id": "12", "text": "已发货待取消" },
			{ "id": "13", "text": "丢件/损坏" },
			{ "id": "14", "text": "已退回" }];
		 function orderstatus(e) {
            for (var i = 0, l = statusList.length; i < l; i++) {
                var g = statusList[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
		
		var intypelist = [
		{ "id": "1", "text": "增票" },
		{ "id": "2", "text": "普票" },
		{ "id": "3", "text": "候补" },
		{ "id": "4", "text": "保卡" },
		{ "id": "5", "text": "不开" },
		]
		function intype(e) {
            for (var i = 0, l = intypelist.length; i < l; i++) {
                var g = intypelist[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
		var line_typelist = [
		{ "id": "1", "text": "主品" },
		{ "id": "2", "text": "赠品" },
		                     ];
		function line_type(e){
			for (var i = 0, l = line_typelist.length; i < l; i++) {
                var g = line_typelist[i];
                if (g.id == e.value) return g.text;
            }
            return "";
		}
		
		 //绘制表格 
		  grid.on("drawcell", function (e) {
	        var record = e.record,
	        column = e.column,
	        field = e.field,
	        value = e.value;
	      
	            //赠品显示红色
	            if (field == "U_Type" && value ==2) {
	               // e.cellStyle = "color:red;font-weight:bold;";
	                e.rowCls = "zengpin";
	            }
	            //设置行样式
	            if (record.gender == 1) {
	                e.rowCls = "myrow";
	            }
	            if(field == 'U_OrderId'){
	            	e.cellHtml = '';
	            	if(record.QryGroup45=='Y'&&record.U_OStatus=='8'&&record.U_IsPick=='Y'){
						 e.cellHtml+= "&nbsp;<a href=\"javascript:shipment(\'"+record.U_OrderId.toString()+"\',\'"+record.DocEntry.toString()+"\',\'"+record.LineId.toString()+"\')\">"+"更新已发货"+"</a>";
				   }
		            
                    e.cellHtml += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:openLifeCycle(\'"+value.toString()+"\',\'"+record.DocEntry.toString()+"\',\'"+record.LineId.toString()+"\')\">"+value.toString()+"</a>";
				

               }

	        });
		
		
		
	   function getboxvalue() {
            var obj = mini.get("statuslist");
            return obj.getValue();
        }

        function search() {
        	
		    mini.get('panel1').setExpanded(false);
			var statuslist = getboxvalue();
		    var U_OTPhone = document.getElementById("U_OTPhone").value;
			var U_CardCode = mini.get("U_CardCode").getValue();
			var U_Phone = document.getElementById("U_Phone").value;
			var U_CitemNm = document.getElementById("U_CitemNm").value;
			var U_OrderId = document.getElementById("U_OrderId").value;
			var U_ItemCode = document.getElementById("U_ItemCode").value;
			var U_InType = mini.get("U_InType").getValue();
			var U_Cstname = document.getElementById("U_Cstname").value;
			var U_CardName = document.getElementById("U_CardName").value;
			var U_CitemCd = document.getElementById("U_CitemCd").value;
			var U_ExpNo = document.getElementById("U_ExpNo").value;
			var U_ownname = document.getElementById("U_ownname").value;
			var U_ItemName = document.getElementById("U_ItemName").value;
			var key={
			U_CardCode: U_CardCode ,
			U_Phone:U_Phone,
			U_CitemNm:U_CitemNm,
			U_OrderId:U_OrderId,
			U_ItemCode:U_ItemCode,
			U_InType:U_InType,
			U_Cstname:U_Cstname,
			U_CardName:U_CardName,
			U_CitemCd:U_CitemCd,
			U_ExpNo:U_ExpNo,
			U_ownname:U_ownname,
			U_ItemName:U_ItemName,
			
			};
			
		
			var docDate1 =   mini.get("docDate1").getValue();
			var docDate2 =    mini.get("docDate2").getValue();
			
			var u_DocDate={start:docDate1,end:docDate2};
			
            grid.load({q:key,statuslist:statuslist,udocdate:u_DocDate});
        }
        function exportExcel() {

            mini.get('panel1').setExpanded(false);
            var statuslist = getboxvalue();
            var U_OTPhone = document.getElementById("U_OTPhone").value;
            var U_CardCode = mini.get("U_CardCode").getValue();
            var U_Phone = document.getElementById("U_Phone").value;
            var U_CitemNm = document.getElementById("U_CitemNm").value;
            var U_OrderId = document.getElementById("U_OrderId").value;
            var U_ItemCode = document.getElementById("U_ItemCode").value;
            var U_InType = mini.get("U_InType").getValue();
            var U_Cstname = document.getElementById("U_Cstname").value;
            var U_CardName = document.getElementById("U_CardName").value;
            var U_CitemCd = document.getElementById("U_CitemCd").value;
            var U_ExpNo = document.getElementById("U_ExpNo").value;
            var U_ownname = document.getElementById("U_ownname").value;
            var U_ItemName = document.getElementById("U_ItemName").value;
            var key={
                U_CardCode: U_CardCode ,
                U_Phone:U_Phone,
                U_CitemNm:U_CitemNm,
                U_OrderId:U_OrderId,
                U_ItemCode:U_ItemCode,
                U_InType:U_InType,
                U_Cstname:U_Cstname,
                U_CardName:U_CardName,
                U_CitemCd:U_CitemCd,
                U_ExpNo:U_ExpNo,
                U_ownname:U_ownname,
                U_ItemName:U_ItemName,

            };


            var docDate1 =   mini.get("docDate1").getValue();
            var docDate2 =    mini.get("docDate2").getValue();

            var u_DocDate={start:docDate1,end:docDate2};

            // $.ajax({
            //     url: 'sapdataexcel.php',
            //     type: 'post',
            //     data: {q:key,statuslist:statuslist,udocdate:u_DocDate},
            //     success: ''
            // });

            var f=document.createElement("form");
            var data = {q:key,statuslist:statuslist,udocdate:u_DocDate};
            var str_pretty1 = JSON.stringify(data)
            f.action="sapdataexcel.php";
            f.method="post";
            f.innerHTML=" <input type='hidden' name='data' value='"+str_pretty1+"'/>";
            document.body.appendChild(f);
            f.submit();

        }
        $("#key").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
        ///////////////////////////////////////////////////////
        var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
        function onGenderRenderer(e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
		
		function ondrawcell(e) {
        var row = e.row,
                column = e.column,
                field = e.field,
                value = e.value;
        //超链接任务
        if (field == "U_ItemCode") {
            e.cellHtml = '<a id="' + row.U_ItemCode + '" class="showCellTooltip" data-placement="bottomleft">' + row.U_ItemCode + '</a>';
        }
    }

    var box;
	 jQuery('.showCellTooltip').live('click',function(){
		 mini.hideMessageBox(box);
		 loading();
		 var id = jQuery(this).html();
		    $.ajax({
	            url: "/sap/getware.php",
	            data: { id: id },
	            async: true,
	            success: function (text) {
	            	 mini.unmask(document.body);
	            	htmlClick(text);
	              
	            }
	        });
		
	 })
		  function loading() {
		        mini.mask({
		            el: document.body,
		            cls: 'mini-mask-loading',
		            html: '加载库存信息..'
		        });
		    
		    }
		    function htmlClick(htmlContent) {
		    	box=  mini.showMessageBox({
		            width: 550,
		            title: "库存情况",
		            html: htmlContent,
		            showModal: false,		            
		        });
		    }
					function onCellValidation(e) {

						if (e.field == "U_Address") {
							if (e.value == '') {
								e.isValid = false;
								e.errorText = "地址不能为空";
							}
						}
					}
					function onButtonEdit(e) {
						var btnEdit1 = e.sender;
						var row = grid.getSelected();
						var json = mini.encode(row);

						mini.open({
							url : "/sap/update.php?data=" + json,
							title : "编辑订单",
							width : 650,
							height : 280,
							onload : function() {
								//                    var iframe = this.getIFrameEl();
								//                    iframe.contentWindow.SetData(null);
							},
							ondestroy : function(action) {
								if (action == "ok") {
									CloseWindow();
									mini.alert('修改成功....');
									grid.reload();
								}
							}
						});
					}

					function CloseWindow(action) {
						if (window.CloseOwnerWindow)
							return window.CloseOwnerWindow(action);
						else
							window.close();
					}

					function openLifeCycle(orderid, DocEntry, LineId) {

	                    //alert(orderid);
	                    //alert(DocEntry);
	                    //alert(LineId);

                        mini.open({
                            url : "/report/getlifecycle/orderid/" + orderid +"/DocEntry/" + DocEntry + "/LineId/" + LineId,
                            title : "平台订单代码: "+orderid,
                            width : 900,
                            height : 450,
                            onload : function() {
                            },
                            ondestroy : function(action) {
                                if (action == "ok") {
                                    CloseWindow();
                                }
                            }
                        });


                    }

                    function shipment(orderid,docentryId,lineid){
                       if(confirm("确定要将订单号:"+orderid+" 更新成已发货吗?")){
                    	   $.ajax({
                               url: "/sap/sapshipment.php",
                               data: { orderId: orderid,docentryId:docentryId, lineId:lineid},
                               type:'post',
                               async: true,
                               success: function (text) {
                               	
                               		mini.alert(text);
                             
                                 
                               }
                           });
                       }
                     }
				</script>

</body>
</html>